package com.csjbot.weedle_auto.app.main

import android.content.Context

import com.csjbot.weedle_auto.app.BaseApplication
import com.csjbot.weedle_auto.util.Csjlogger

import com.google.common.base.Preconditions.checkNotNull

/**
 * author : chenqi.
 * e_mail : 1650699704@163.com.
 * create_time : 8/18/17.
 */

class MainPresenter(view: MainContract.view, context: Context) : MainContract.presenter {
    private val mview: MainContract.view = checkNotNull(view, "taskDetailView cannot be null!")
    private val application: BaseApplication

    init {
        mview.setPresenter(this)
        application = context.applicationContext as BaseApplication
    }

    override fun start() {
        //打开监听
    }


    override fun openSerialPort(bt: String, pt: Int) {
        Csjlogger.info("chenqi :::::1{}{}" + bt + pt)
        if (bt.equals("", ignoreCase = true) || pt == 0) {
            val path = "/dev/ttyS4"//路径
            val backdate = 115200//波特率
            Csjlogger.info("chenqi :::::2{}{}" + bt + pt)
            BaseApplication.instance.serial.openSerialPort(backdate, path)
        } else
            BaseApplication.instance.serial.openSerialPort(pt, bt)
    }

    override fun closeSerial() {}
}
